package RSS.reader;

import RSS.bean.CommonInformationItem;
import RSS.bean.RSSDataCapturer;
import RSS.buffer.NewsBuffer;
import org.apache.log4j.Logger;

import java.util.List;


/**
 * @program: gitee4_socket
 * @description: 下载RSS源中的新闻item任务类
 * @author: zy
 * @create: 2024-07-24 16:58
 */
public class NewsProductTask    implements Runnable {
    private String name;
    private String url;
    private NewsBuffer newsBuffer;

    private Logger log= Logger.getLogger(    NewsProductTask.class.getName());

    public NewsProductTask(String name, String url, NewsBuffer newsBuffer) {
        this.name = name;
        this.url = url;
        this.newsBuffer = newsBuffer;
    }


    @Override
    public void run() {
        RSSDataCapturer capturer=new RSSDataCapturer(   name );
        List<CommonInformationItem> list= capturer.load(   url );
        //存到缓存队列中
        for(  CommonInformationItem item:list){
            newsBuffer.add( item );
        }
        log.info("下载:"+name+"源的"+url+"的新闻成功");
    }
}
